home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Headers / misckit / MiscSubprocess.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-21  |  5.7 KB  |  198 lines

  1. //
  2. //    MiscSubprocess.h -- a Obj-C wrapper around Unix child processes
  3. //        Originally written by Drew Davidson
  4. //        Copyright (c) 1994 by Drew Davidson.
  5. //        Modified by Don Yacktman for inclusion into the MiscKit.
  6. //        Fixed up by Carl Lindberg, Don Yacktman, and Steve Hayman.
  7. //                Version 1.3.  All rights reserved.
  8. //        This notice may not be removed from this source code.
  9. //
  10. //    This object is included in the MiscKit by permission from the author
  11. //    and its use is governed by the MiscKit license, found in the file
  12. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  13. //    for a list of all applicable permissions and restrictions.
  14. //    
  15.  
  16. /*----------------------------------------------------------------------------
  17.     $Source$
  18.  
  19.   This subprocess object sends/receives data to/from any UNIX
  20.   subprocess asynchronously (via vfork/pipe).
  21.   Its delegate, if any, will receive the following messages:
  22.  
  23.     - subprocess:sender done:(int)status :(MiscSubprocessEndCode)code;
  24.         Sent when the subprocess exits.  If code indicates what status
  25.         will be:
  26.         
  27.             Misc_Exited
  28.                 status is the exit code returned by the process.
  29.                 
  30.             Misc_Stopped
  31.                 status is the signal that caused the subprocess
  32.                 to stop.
  33.                 
  34.             Misc_Signaled
  35.                 status is the signal that caused the subprocess to
  36.                 terminate
  37.                 
  38.             Misc_UnknownEndCode
  39.                 status == 0.
  40.   
  41.     - subprocess:sender output:(char *)buffer;
  42.         sent whenever there is data on the standard output pipe;
  43.         buffer is only valid until next call
  44.  
  45.     - subprocess:sender stderrOutput:(char *)buffer;
  46.         sent whenever there is data on the standard error pipe;
  47.         buffer is only valid until next call.
  48.  
  49.     - subprocess:sender error:(const char *)errorString;
  50.         sent when an error occurs;
  51.         if it ever happens, it's usually only at startup time
  52.         (has nothing to do with errors in the subprocess, but
  53.         rather in starting/stopping/etc. the process)
  54.  
  55.     The object keeps a MiscStringArray of strings to be used as the
  56.     environment for the exec'd subprocess.  It is accessible through
  57.     the environment method.
  58.     
  59.     REVISIONS
  60.     $Log$
  61. ----------------------------------------------------------------------------*/
  62. # import <stdio.h>
  63. # import <objc/Object.h>
  64. # import <misckit/MiscStringArray.h>
  65.  
  66. typedef enum
  67. {    Misc_Exited,
  68.     Misc_Stopped,
  69.     Misc_Signaled,
  70.     Misc_UnknownEndCode
  71. } MiscSubprocessEndCode;
  72.  
  73. @interface MiscSubprocess:Object
  74. {    /*
  75.      * Outlets
  76.      */
  77.     id        delegate;
  78.  
  79.     /*
  80.      * Other instance variables
  81.      */
  82.     id        environment;
  83.     FILE    *fpToChild;
  84.     FILE    *fpFromChild;
  85.     int        stdoutFromChild;
  86.     int        stderrFromChild;
  87.     int        childPid;
  88.     id        stdoutBuffer;
  89.     id        stderrBuffer;
  90.     int        masterPty;
  91.     int        slavePty;
  92.     BOOL    paused;
  93.     BOOL    running;
  94.     BOOL    usePtys;
  95.     BOOL    asynchronous;
  96.     char *execArgs[3];
  97.     
  98.     /*
  99.      * stdoutIsDone, stderrIsDone record whether we've seen
  100.      * eof on those file descriptors
  101.      */
  102.     BOOL    stdoutIsDone, stderrIsDone;
  103.     int    dpsStdoutFromChild, dpsStderrFromChild;
  104. }
  105.  
  106. /*
  107.  * Designated initializer for MiscSubprocess.  If aString is NULL
  108.  * then nothing is executed.  Normally you will want flag==YES, but
  109.  * we leave you the option, Just In Case(TM).  If you use async=NO
  110.  * then we don't return until the subprocess exits.
  111.  */
  112. - init:(const char *)aString withDelegate:theDelegate
  113.         keepEnvironment:(BOOL)flag withPtys:(BOOL)ptyFlag
  114.         asynchronously:(BOOL)async;
  115.  
  116. /*
  117.  * Externally callable routine to initiate the execution of
  118.  * the command aString.
  119.  */
  120. - execute:(const char *)aString withPtys:(BOOL)ptyFlag
  121.     asynchronously:(BOOL)async;
  122.  
  123. /*
  124.  * Called by execute: to perform the exec function.
  125.  * Override to call something other than the default execle().
  126.  */
  127. - execChild:(const char *)aString;
  128.  
  129. - setExecArgs:(const char *)a0 :(const char *)a1 :(const char *)a2;
  130.  
  131. - setDelegate:anObject;
  132. - delegate;
  133.  
  134. - environment;
  135.  
  136. - (SEL)outputMethodForBuffer:aBuffer;
  137. - flushBuffer:aString as:aBuffer;
  138. - flushBuffer:aString;
  139.  
  140. - send:(const char *)string withNewline:(BOOL)wantNewline;
  141. - send:(const char *)string;
  142. - (int)pid;
  143. - pause:sender;
  144. - resume:sender;
  145. - (BOOL)isPaused;
  146. - (BOOL)isRunning;
  147. - terminate:sender;
  148. - terminateInput;
  149. - (BOOL)usePtys;
  150. - setUsePtys:(BOOL)flag;
  151. - (BOOL)asynchronous;
  152. - setAsynchronous:(BOOL)flag;
  153.  
  154. @end
  155.  
  156. @interface Object(MiscSubprocessDelegate)
  157.  
  158. - subprocess:sender done:(int)status :(MiscSubprocessEndCode)code;
  159. - subprocess:sender output:(const char *) buffer;
  160. - subprocess:sender stderrOutput:(const char *)buffer;
  161. - subprocess:sender error:(const char *)errorString;
  162.  
  163. @end
  164.  
  165. @interface MiscSubprocess(Convenience)
  166.  
  167. // These were automatically generated using cnvwrap.
  168.  
  169. - init;
  170. - init:(const char *)aString;
  171. - init:(const char *)aString withDelegate:theDelegate;
  172. - init:(const char *)aString keepEnvironment:(BOOL)flag;
  173. - init:(const char *)aString withDelegate:theDelegate
  174.         keepEnvironment:(BOOL)flag;
  175. - init:(const char *)aString withPtys:(BOOL)ptyFlag;
  176. - init:(const char *)aString withDelegate:theDelegate withPtys:(BOOL)ptyFlag;
  177. - init:(const char *)aString keepEnvironment:(BOOL)flag withPtys:(BOOL)ptyFlag;
  178. - init:(const char *)aString withDelegate:theDelegate
  179.         keepEnvironment:(BOOL)flag withPtys:(BOOL)ptyFlag;
  180. - init:(const char *)aString asynchronously:(BOOL)async;
  181. - init:(const char *)aString withDelegate:theDelegate
  182.         asynchronously:(BOOL)async;
  183. - init:(const char *)aString keepEnvironment:(BOOL)flag
  184.         asynchronously:(BOOL)async;
  185. - init:(const char *)aString withDelegate:theDelegate
  186.         keepEnvironment:(BOOL)flag asynchronously:(BOOL)async;
  187. - init:(const char *)aString withPtys:(BOOL)ptyFlag asynchronously:(BOOL)async;
  188. - init:(const char *)aString withDelegate:theDelegate withPtys:(BOOL)ptyFlag
  189.         asynchronously:(BOOL)async;
  190. - init:(const char *)aString keepEnvironment:(BOOL)flag withPtys:(BOOL)ptyFlag
  191.         asynchronously:(BOOL)async;
  192.  
  193. - execute:(const char *)aString;
  194. - execute:(const char *)aString withPtys:(BOOL)ptyFlag;
  195. - execute:(const char *)aString asynchronously:(BOOL)async;
  196.  
  197. @end
  198.